<template>
  <div class="ProducthHmPg">
    <div class="incolumn_countr" v-if="show_faBu==true">
      <div class="search-box" >
        <hy-search
          ref="query"
          :searchTitle="searchTitle"
          v-model="searcher"
          :button="{btnShowBy3:true}"
          :buttonText="{btnNameBy3:'发布任务'}"
          :col="6"
          @search="getData(0)"
          @clickbybtn3="clickBy3"
        ></hy-search>
      </div>
    </div>
    <div class="table-box">
      <template>
        <el-table :data="tableData" stripe style="width:100%" :height="autoHeightTable">
          <el-table-column prop="xuhao" label="序号" width="100" align="center"></el-table-column>
          <el-table-column prop="createOnStr" label="发布日期" align="center"></el-table-column>
          <el-table-column prop="essence" label="接收" align="center"></el-table-column>
          <el-table-column prop="typeStr" label="任务类型" align="center"></el-table-column>
          <el-table-column prop="title" label="任务主题" show-overflow-tooltip align="center"></el-table-column>
          <el-table-column prop="date" label="完成日期" align="center"></el-table-column>
          <el-table-column prop="creater" label="发布人" align="center"></el-table-column>
          <el-table-column prop="receiver" label="接收人" align="center"></el-table-column>
          <el-table-column prop="stateStr" label="状态" align="center"></el-table-column>
          <el-table-column label="操作" width="300" align="center">
            <template slot-scope="scope">
              <el-button
                type="warning"
                size="mini"
                v-show="scope.row.stateInt ==1"
                @click="taskDetail(scope.row.id,0)"
              >接收</el-button>
              <el-button
                type="warning"
                size="mini"
                v-show="scope.row.stateInt == 2"
                @click="taskDetail(scope.row.id,0)"
              >完成</el-button>
              <el-button
                type="warning"
                size="mini"
                v-show="scope.row.stateInt == 3"
                @click="taskDetail(scope.row.id,0)"
              >审核</el-button>
              <el-button type="primary" size="mini" @click="taskDetail(scope.row.id,1)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <template>
      <el-pagination
        background
        layout="prev, pager, next"
        :total="total"
        :current-page="current"
        :page-size="pagesize"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </template>
  </div>
</template>

<script>
import axios from "axios";
export default {
  components: {},
  computed: {
    autoHeightTable () {
      return document.documentElement.scrollHeight - 251 - 82;
    }
  },
  data () {
    return {
      show_faBu:true,//是否展示发布任务按钮
      searchTitle: [
        {
          type: "input",
          name: "customProductName",
          label: "输入搜索",
          placeholder: "请输入任务主题",
          prop: "customProductName"
        },

        {
          type: "date2",
          name: "issuanceDate",
          label: "输入时间",
          placeholder: "请选择输入时间",
          prop: "issuanceDate"
        }
      ],
      searcher: {
        customProductName: "",
        customProductNo: "",
        issuanceDate: ""
      },
      total: 0,
      current: 1,
      pagesize: 10,
      tableData: []
    };
  },
  created () {
    this.creater = JSON.parse(localStorage.getItem("message")).Id;
    this.getData(0);
    const message=JSON.parse(localStorage.getItem("message"))
    console.log(message.RoleLevelInt==25)
    if (message.RoleLevelInt==25||message.RoleLevelInt==30) {
      this.show_faBu=false
    }
  },
  methods: {
    // 首页列表数据
    getData (page) {
      let start = ""; let end = "";
      if (this.searcher.issuanceDate != null && this.searcher.issuanceDate != "") { start = this.searcher.issuanceDate[0]; end = this.searcher.issuanceDate[1]; }
      let obj = {
        pn: page,
        PerPageSize: 10,
        key: this.searcher.customProductName ? this.searcher.customProductName : "",
        start: start,
        end: end,
        creater: this.creater
      };
      var objs = JSON.stringify(obj);
      //console.log(objs)
      axios("/apis/MyCenter.asmx/GetData?index=2&jsondata=" + objs).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        var list = JSON.parse(datas.string.__text);
        this.total = list.count; let a = 10 * page;
        for (var i = 0; i < list.data.length; i++) { list.data[i].xuhao = ++a; }
        this.tableData = list.data;
        //console.log(list);
      });
    },
    //发布任务
    clickBy3 () {
      this.$router.push("./AddTask");
    },
    //详情
    taskDetail (e, shows) {
      this.$router.push({ path: "./TaskDetail", query: { e: e, shows: shows } });
    },
    // 分页
    handleCurrentChange (e) {
      this.getData(e - 1);
    }
  }
};
</script>

<style lang="scss" scoped src="@/assets/scss/base.scss">

.incolumn_countr {
  width: 97%;
}
.el-pagination {
  margin-top: 15px;
  text-align: center;
}

.table-box {
  width: 98%;
  margin-left: 15px;
}
</style>
<style >
.incolumn_countr .yy-search .btn {
  margin-left: 0px;
  margin-right: 45px;
}
</style>
